package com.ym.medical.service.impl;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaUserService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.core.util.RandomUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ym.base.enums.FlagEnum;
import com.ym.common.constant.Constants;
import com.ym.common.constant.UserDetails;
import com.ym.common.enums.LoginMethodEnum;
import com.ym.common.enums.SmsTemplateEnum;
import com.ym.common.enums.UserUserTypeEnum;
import com.ym.common.utils.HttpUtil;
import com.ym.common.utils.IpUtil;
import com.ym.common.utils.ServletUtil;
import com.ym.core.config.ConfigCenterProperties;
import com.ym.core.config.YunxinConfig;
import com.ym.core.exception.BusinessException;
import com.ym.core.shiro.ShiroTokenManager;
import com.ym.core.shiro.ShiroUtil;
import com.ym.core.shiro.token.UserAccToken;
import com.ym.core.shiro.token.UserSmsToken;
import com.ym.core.shiro.token.WxToken;
import com.ym.core.utils.Assert;
import com.ym.core.utils.tkmybatis.BaseSVImpl;
import com.ym.core.utils.tkmybatis.TK;
import com.ym.medical.dao.AccountDao;
import com.ym.medical.dao.BankcardDao;
import com.ym.medical.dao.UserDao;
import com.ym.medical.dao.UserDoctorViewDao;
import com.ym.medical.domain.entity.AccountEntity;
import com.ym.medical.domain.entity.BankcardEntity;
import com.ym.medical.domain.entity.SysSignEntity;
import com.ym.medical.domain.entity.UserEntity;
import com.ym.medical.domain.entity.UserPatientViewEntity;
import com.ym.medical.domain.entity.WxUserEntity;
import com.ym.medical.domain.entity.YunxinUserEntity;
import com.ym.medical.domain.param.UserParam;
import com.ym.medical.domain.vo.DoctorVo;
import com.ym.medical.domain.vo.LoginVO;
import com.ym.medical.domain.vo.PatientVo;
import com.ym.medical.domain.vo.UserDoctViewVo;
import com.ym.medical.enums.FileTypeEnum;
import com.ym.medical.enums.OrgEnum;
import com.ym.medical.enums.OrgSignEnum;
import com.ym.medical.enums.SmsCodeTypeEnum;
import com.ym.medical.enums.UserCertStateEnum;
import com.ym.medical.enums.UserSexEnum;
import com.ym.medical.enums.UserUserStateEnum;
import com.ym.medical.service.*;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.apache.shiro.authc.DisabledAccountException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.pam.UnsupportedTokenException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 终端用户Service业务层处理
 *
 * @author ym
 * @date 2020-08-17
 */
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class UserSVImpl extends BaseSVImpl<UserEntity, UserDao> implements IUserSV {

	@Resource
	private WxMaService wxMaService;

	@Autowired
	private WxMpService wxMpService;

	@Autowired
	private IUserPatientViewSV userPatientViewSV;

	@Autowired
	private IUserDoctorViewSV userDoctorViewSV;

	@Autowired
	private ISysSignSV sysSignSV;

	@Autowired
	private IWxUserSV wxUserSV;

	@Autowired
	private IYunxinUserSV yunxinUserSV;

	@Autowired
	private ISysConfigSV sysConfigSV;

	@Autowired
	private IAccountSV accountSV;

	@Autowired
	private IFileInforSV fileInforSV;

	@Autowired
	private ConfigCenterProperties configCenterProperties;

	@Autowired
	private IMessageCodeSV messageCodeSV;

	@Autowired
	private ISysSignSV iSysSignSV;


	@Autowired
	private AccountDao accountDao;

	@Autowired
	private IDoctorDetailSV iDoctorDetailSV;

	@Autowired
	private BankcardDao bankcardDao;

	@Autowired
	private UserDoctorViewDao userDoctorViewDao;


	/**
	 * 更新登录相关额外信息
	 *
	 * @param userId
	 */
	private void updateLoginInfo(Long userId, String device) {
		UserEntity userEntity = new UserEntity();
		userEntity.setId(userId);
		userEntity.setLastLoginTime(new Date());
		userEntity.setLoginDevice(device);
		userEntity.setLoginIp(IpUtil.getIpAddr(ServletUtil.getRequest()));
		this.updateById(userEntity);
	}


	/**
	 * 初始化用户
	 *
	 * @param code   微信code
	 * @param signId 签名ID
	 * @return
	 */
	private UserEntity initUser(Long signId, WxToken code) {
		UserEntity userEntity = new UserEntity();
		userEntity.setSignId(signId);
		userEntity.setUserState(UserUserStateEnum.TOURISTS.getKey());
		userEntity.setCertState(UserCertStateEnum.UNAUTHORIZED.getKey());
		userEntity.setNickName(RandomUtil.randomString(10));
		userEntity.setSex(UserSexEnum.UNKNOWN.getKey());
		userEntity.setCertState(UserCertStateEnum.UNAUTHORIZED.getKey());
		userEntity.setUserType(code.getUserType().getKey());
		// 密码设置
		String salt = RandomUtil.randomString(6);
		userEntity.setSalt(salt);
		String defaultPassword = sysConfigSV.getValueByKey(Constants.SysConfigKey.DEFAULT_PASSWORD);
		userEntity.setUserPwd(ShiroUtil.genHashPass(defaultPassword, salt));
		this.insert(userEntity);
		return userEntity;
	}

	@Override
	public String authorizedPhone(long userId, String phoneNumber) {
		//1.检测是否已经有该手机号码注册,且不是当前登录人
		UserEntity exitUser = this.selectByPhone(phoneNumber, UserUserTypeEnum.PATIENT);
		if (exitUser != null && exitUser.getId() != userId) {
			Long exitId = exitUser.getId();
			UserEntity currUser = this.selectById(userId);
			currUser.setPhoneNo(phoneNumber);
			BeanUtil.copyProperties(currUser, exitUser);
			this.deleteById(currUser.getId());
			this.updateByParams(exitUser, SelectWhere().andEqualTo(UserEntity::getId, exitId).end());
		} else {
			// 手机号码更新
			UserEntity user = new UserEntity();
			user.setId(userId);
			user.setPhoneNo(phoneNumber);
			this.updateById(user);
		}
		WxUserEntity wxUser = new WxUserEntity();
		wxUser.setIsAuthPhone(FlagEnum.IS.getKey());
		wxUserSV.updateByParams(wxUser, TK.selectWhere(WxUserEntity.class).andEqualTo(WxUserEntity::getUserId, userId).end());
		log.info("用户[{}]授权手机号", phoneNumber);
		return phoneNumber;
	}

	@Override
	public UserEntity selectByPhone(String phoneNumber, UserUserTypeEnum userUserType) {
		UserEntity exitUser = this.selectOne(SelectWhere()
				.andEqualTo(UserEntity::getPhoneNo, phoneNumber)
				.andEqualTo(UserEntity::getUserType, userUserType.getKey())
				.end()
		);
		return exitUser;
	}


	/***
	 * 账号禁用
	 * @param userIds
	 * @return
	 */
	@Override
	public int disableUser(Long[] userIds, UserUserTypeEnum userType) {
		Assert.isEmpty(userIds, "请选择至少一个用户!");
		int rows = this.updateByParams(
				UserEntity.builder().userState(UserUserStateEnum.DISABLE.getKey()).build(),
				SelectWhere().andIn(UserEntity::getId, userIds).end()
		);
		// 执行踢出用户操作
		for (Long userId : userIds) {
			ShiroTokenManager.kickOutUser(userId, userType);
		}
		return rows;
	}

	/***
	 * 账号禁用
	 * @param userIds
	 * @return
	 */
	@Override
	public int enableUser(Long[] userIds, UserUserTypeEnum userType) {
		Assert.isEmpty(userIds, "请选择至少一个用户!");
		int rows = this.updateByParams(
				UserEntity.builder().userState(UserUserStateEnum.NORMAL.getKey()).build(),
				SelectWhere().andIn(UserEntity::getId, userIds).end()
		);
		return rows;
	}

	/**
	 * 刷新shiro当前患者用户信息
	 *
	 * @return
	 */
	@Override
	public void refreshPatientUser() {
		UserPatientViewEntity wxUserDetailOld = ShiroUtil.getLoginUser(UserPatientViewEntity.class, true);
		if (wxUserDetailOld == null) {
			return;
		}
		UserPatientViewEntity userPatientViewEntity = userPatientViewSV.selectById(wxUserDetailOld.getId());
		userPatientViewEntity.setSessionKey(wxUserDetailOld.getSessionKey());
		ShiroUtil.setLoginUser(userPatientViewEntity);
	}

	@Override
	public LoginVO authorizeInfo(UserPatientViewEntity wxUserDetail, String encryptedData, String iv, Long recommendUserId) {

		WxMaUserInfo userInfo = wxMaService.getUserService().getUserInfo(wxUserDetail.getSessionKey(), encryptedData, iv);
		// 1.同步授权信息到微信表
		WxUserEntity wxUserEntity = wxUserSV.synchronizeWeChatDataMa(wxUserDetail.getId(), userInfo);
		// 2.同步微信信息到用户表
		this.synchronizedWxUserToUser(wxUserEntity);

		// 登录信息返回
		LoginVO loginVO = new LoginVO();
		UserEntity userEntity = this.selectById(wxUserDetail.getId());
		// 3.获取云信账户
		YunxinUserEntity yunxinAcc = yunxinUserSV.createYxUserAccount(userEntity);
		loginVO.setYunxinPwd(yunxinAcc.getToken());
		loginVO.setYunxinAcc(yunxinAcc.getAccid());

		// 4.获取签名
		SysSignEntity signByUser = sysSignSV.selectById(wxUserDetail.getSignId());
		loginVO.setAppKey(signByUser.getAppKey());

		loginVO.setHeadUrl(userEntity.getHeadUrl());
		loginVO.setPhoneAuthorize(FlagEnum.IS.getKey().equals(wxUserEntity.getIsAuthPhone()));
		loginVO.setInfoAuthorize(true);
		loginVO.setName(userEntity.getNickName());
		loginVO.setAuthorization(ShiroUtil.getSessionId());
		loginVO.setLoginId(userEntity.getId());

		// 云信token返回
		YunxinConfig yunxinConfig = configCenterProperties.getYunxinConfig();
		loginVO.setAccid(yunxinConfig.getCustomerAccid());
		loginVO.setToken(yunxinConfig.getCustomerToken());
		return loginVO;
	}

	/**
	 * 同步微信表数据到用户表
	 *
	 * @param wxUser
	 */
	private void synchronizedWxUserToUser(WxUserEntity wxUser) {
		if (wxUser.getUserId() == null) {
			throw new UnsupportedOperationException("不支持的操作!");
		}
		UserEntity userEntity = new UserEntity();
		userEntity.setId(wxUser.getUserId());
		userEntity.setNickName(wxUser.getWxUserNc());
		userEntity.setSex(wxUser.getGender());
		// 将微信头像存储在本地，并设置用户头像为微信头像
		byte[] bytes = HttpUtil.get(wxUser.getWxTxUrl()).bytes();
		String fieldId = fileInforSV.uploadFile(bytes, FileTypeEnum.IMG, wxUser.getWxUserNc(), "user", "head_url", "微信头像", wxUser.getUserId());
		userEntity.setHeadUrl(fieldId);
		this.updateById(userEntity);
	}

	@Override
	public UserDetails loginByAccountPwd(UserAccToken userAccToken) {
		UserDetails userDetails = null;
		// 根据账号查找用户
		UserEntity userEntity = this.selectByPhone(userAccToken.getAccount(), userAccToken.getUserType());
		// 如果找不到
		if (userEntity == null) {
			throw new UnknownAccountException();
		}
		// 如果禁用
		String userState = userEntity.getUserState();
		if (UserUserStateEnum.DISABLE.getKey().equals(userState)) {
			throw new DisabledAccountException();
		}
		// 判断登录的用户类型
		UserUserTypeEnum userType = userAccToken.getUserType();
		switch (userType) {
			case PATIENT:
				userDetails = userPatientViewSV.selectById(userEntity.getId());
				break;
			case DOCTOR:
				userDetails = userDoctorViewSV.selectById(userEntity.getId());
				break;
		}
		if (userDetails.getId() != null) {
			// 登录方式确定
			userDetails.setLoginMethod(LoginMethodEnum.ACC_PWD);
			// 更新登录信息
			updateLoginInfo(userDetails.getId(), userAccToken.getDevice());
		}
		return userDetails;
	}

	@Override
	public UserDetails loginByAccountSms(UserSmsToken userSmsToken) {
		UserDetails userDetails = null;
		// 根据账号查找用户
		UserEntity userEntity = this.selectByPhone(userSmsToken.getAccount(), userSmsToken.getUserType());
		// 如果找不到
		if (userEntity == null) {
			throw new UnknownAccountException();
		}
		// 判断验证码是否正确
		boolean isTrue = messageCodeSV.validatePhoneCode(userSmsToken.getAccount(), SmsCodeTypeEnum.APP_NOT_EXIST_TELL_ME, SmsTemplateEnum.LOGON_CONFIRMATION_AUTHENTICATION_CODE, userSmsToken.getSmsCode());
		Assert.isFalse(isTrue, "短信验证码不正确!");

		// 如果禁用
		String userState = userEntity.getUserState();
		if (UserUserStateEnum.DISABLE.getKey().equals(userState)) {
			throw new DisabledAccountException();
		}
		// 判断登录的用户类型
		UserUserTypeEnum userType = userSmsToken.getUserType();
		switch (userType) {
			case PATIENT:
				userDetails = userPatientViewSV.selectById(userEntity.getId());
				break;
			case DOCTOR:
				userDetails = userDoctorViewSV.selectById(userEntity.getId());
				break;
		}
		if (userDetails.getId() != null) {
			updateLoginInfo(userDetails.getId(), userSmsToken.getDevice());
		}
		userDetails.setLoginMethod(LoginMethodEnum.ACC_SMS);
		return userDetails;
	}

	@Override
	public UserDetails loginByWxToken(WxToken wxToken) {
		UserPatientViewEntity userDetails = null;
		UserUserTypeEnum userType = wxToken.getUserType();
		LoginMethodEnum wxLoginMethod = wxToken.getWxLoginMethod();
		//  患者微信登录处理
		if (userType == UserUserTypeEnum.PATIENT) {
			switch (wxLoginMethod) {
				case SMALL_PROGRAM:
					userDetails = miniLogin(wxToken);
					break;
				case WECHAT_PULL_AUTH:
					userDetails = h5AuthLogin(wxToken);
					break;
			}
		}
		if (userDetails.getId() != null) {
			// 设置登录方式
			userDetails.setLoginMethod(wxToken.getWxLoginMethod());
			// 更新登录信息
			updateLoginInfo(userDetails.getId(), wxToken.getDevice());
		}
		return userDetails;
	}

	/**
	 * 微信H5授权登录
	 *
	 * @param wxToken
	 * @return
	 */
	private UserPatientViewEntity h5AuthLogin(WxToken wxToken) {
		try {
			// 通过code在微信平台验证登陆
			WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wxMpService.oauth2getAccessToken(wxToken.getCode());
			String openId = wxMpOAuth2AccessToken.getOpenId();
			String unionId = wxMpOAuth2AccessToken.getUnionId();
			String scope = wxMpOAuth2AccessToken.getScope();
			// 如果是授权登录,拉取用户信息
			WxMpUser wxMpUser = null;
			if (scope.equals(WxConsts.OAuth2Scope.SNSAPI_USERINFO)) {
				// 没有获取用户信息，需要拉取用户信息
				wxMpUser = wxMpService.oauth2getUserInfo(wxMpOAuth2AccessToken, "zh_CN");
			} else {
				wxMpUser = new WxMpUser();
				wxMpUser.setUnionId(unionId);
				wxMpUser.setOpenId(openId);
			}
			// 检查是否存在账号
			UserPatientViewEntity userPatientViewEntity = userPatientViewSV.selectByWxId(unionId, null, openId);
			if (userPatientViewEntity == null) {
				// 不存在创建账号.此处是视图,所以创建sys_sign/user/wx_user/yunxin_user
				// 1.创建签名
				SysSignEntity signByUser = sysSignSV.createSign(OrgSignEnum.terminalCovert(wxToken.getUserType()));
				// 2.创建用户
				UserEntity userEntity = this.initUser(signByUser.getId(), wxToken);
				// 3.创建微信用户
				wxUserSV.createWxUserMp(userEntity.getId(), wxToken.getUserType(), wxMpUser);
				// 4.创建用户账户
				accountSV.createAccount(userEntity.getId());
				// 5.创建云信账号
				yunxinUserSV.createYxUserAccount(userEntity);
				// 6. 再次查询出用户
				userPatientViewEntity = userPatientViewSV.selectByWxId(unionId, null, openId);
			}
			// 6.userDetails 构建
			return userPatientViewEntity;
		} catch (WxErrorException e) {
			log.error(ExceptionUtil.stacktraceToString(e));
			throw new UnsupportedTokenException();

		}
	}

	/**
	 * 小程序登录
	 *
	 * @param wxToken
	 * @return
	 */
	private UserPatientViewEntity miniLogin(WxToken wxToken) {
		try {
			// 通过code在微信平台验证登陆
			WxMaUserService userService = wxMaService.getUserService();
			WxMaJscode2SessionResult session = userService.getSessionInfo(wxToken.getCode());
			WxMaUserInfo wxMaUserInfo = new WxMaUserInfo();
			wxMaUserInfo.setUnionId(session.getUnionid());
			wxMaUserInfo.setOpenId(session.getOpenid());
			String sessionKey = session.getSessionKey();
			// 检查是否存在账号
			UserPatientViewEntity userPatientViewEntity = userPatientViewSV.selectByWxId(wxMaUserInfo.getUnionId(), wxMaUserInfo.getOpenId(), null);
			if (userPatientViewEntity == null) {
				// 不存在创建账号.此处是视图,所以创建sys_sign/user/wx_user/yunxin_user
				// 1.创建签名
				SysSignEntity signByUser = sysSignSV.createSign(OrgSignEnum.terminalCovert(wxToken.getUserType()));
				// 2.创建用户
				UserEntity userEntity = this.initUser(signByUser.getId(), wxToken);
				// 3.创建微信用户
				wxUserSV.createWxUserMa(userEntity.getId(), wxToken.getUserType(), wxMaUserInfo);
				// 4.获取用户账户
				accountSV.createAccount(userEntity.getId());
				// 5. 再次查询出用户
				userPatientViewEntity = userPatientViewSV.selectByWxId(wxMaUserInfo.getUnionId(), wxMaUserInfo.getOpenId(), null);
			}
			// 如果禁用
			String userState = userPatientViewEntity.getUserState();
			if (UserUserStateEnum.DISABLE.getKey().equals(userState)) {
				throw new DisabledAccountException();
			}
			// 6.userDetails 构建
			userPatientViewEntity.setSessionKey(sessionKey);
			return userPatientViewEntity;
		} catch (WxErrorException e) {
			log.error(ExceptionUtil.stacktraceToString(e));
			throw new UnsupportedTokenException();
		}
	}

	@Override
	public UserEntity findById(Long userId) {
		return this.selectById(userId);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public UserEntity existingUser(String phone, String userType) {
		// 查询账号是否存在
		UserEntity user = this.selectOne(UserEntity.builder().phoneNo(phone).userType(userType).build());
		if (user == null) {
			throw new UnknownAccountException();
		}
		return user;
	}

	@Override
	public UserEntity selectByNameAndPh(String realName, String phoneNo) {
		return mapper.selectByNameAndPh(realName, phoneNo);
	}

	/***
	 * 患者账号列表
	 * @param pageNo
	 * @param limit
	 * @param userModel
	 * @return
	 */
	@Override
	public PageInfo<PatientVo> getPatientList(int pageNo, int limit, UserParam userModel, String blankUserSate) {
		if (blankUserSate == null || "".equals(blankUserSate)) {
			userModel.setUserType("01");
		} else {
			userModel.setUserType("");
		}
		PageHelper.startPage(pageNo, limit);
		List<PatientVo> patientUserList = mapper.getPatientList(userModel, blankUserSate);
		PageInfo<PatientVo> userPageInfo = new PageInfo<>(patientUserList);
		return userPageInfo;
	}

	/**
	 * 医生账号列表
	 *
	 * @param pageNo
	 * @param limit
	 * @param userModel
	 * @return
	 */
	@Override
	public PageInfo<DoctorVo> getDoctorList(int pageNo, int limit, UserParam userModel) {
		PageHelper.startPage(pageNo, limit);
		List<DoctorVo> doctorVoList = mapper.getDoctorList(userModel);
		PageInfo<DoctorVo> doctorVoPageInfo = new PageInfo<>(doctorVoList);
		return doctorVoPageInfo;
	}

	/**
	 * 添加患者账号
	 *
	 * @param user
	 * @return
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public int addPatient(UserParam user) {
		if (null == user) {
			throw new BusinessException("保存对象不能为空");
		}
		if (StringUtils.isEmpty(user.getPhoneNo())) {
			throw new BusinessException("电话号码不能为空");
		}
		if (StringUtils.isEmpty(user.getRealName())) {
			throw new BusinessException("姓名不能为空不能为空");
		}
		user.setCreateTime(new Date());
		user.setModifyTime(new Date());
		user.setUserType("01");
		user.setCertState("01");
		int rows = mapper.insertSelective(user.covert());
		Long userId = user.getId();
		//签名
		SysSignEntity sysSign = iSysSignSV.createSignByUser(OrgEnum.DOCTORS, userId);
		Long signId = sysSign.getId();
		user.setSignId(signId);
		mapper.updateByPrimaryKeySelective(user.covert());
		//创建云信账户
		yunxinUserSV.createYunxinAcc(userId);

		AccountEntity account = new AccountEntity();
		account.setUserId(user.getId());
		account.setAccBalance(BigDecimal.valueOf(0.00));
		account.setFreezeBalance(BigDecimal.valueOf(0.00));
		accountDao.insertSelective(account);

		return rows;
	}

	/**
	 * 医生账号添加
	 *
	 * @param userModel
	 * @return
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public int addDoctor(UserParam userModel) {
		if (null == userModel) {
			throw new BusinessException("保存对象不能为空");
		}
		userModel.setCreateTime(new Date());
		userModel.setModifyTime(new Date());
		userModel.setUserType("02");
		userModel.setCertState("01");
		mapper.insertSelective(userModel.covert());
		Long userId = userModel.getId();

		//签名
		SysSignEntity sysSign = iSysSignSV.createSignByUser(OrgEnum.DOCTORS, userId);
		Long signId = sysSign.getId();
		userModel.setSignId(signId);
		mapper.updateByPrimaryKeySelective(userModel.covert());


		//创建云信账户
		yunxinUserSV.createYunxinAcc(userId);
		//初始化通讯录
		iDoctorDetailSV.createDoctAddressBook(userId);


		AccountEntity account = new AccountEntity();
		account.setUserId(userModel.getId());
		account.setAccBalance(BigDecimal.valueOf(0.00));
		account.setFreezeBalance(BigDecimal.valueOf(0.00));
		accountDao.insertSelective(account);


		BankcardEntity bankcard = new BankcardEntity();
		bankcard.setUserId(userModel.getId());
		bankcard.setBankName(userModel.getBankName());
		bankcard.setBcNumber(userModel.getBcNumber());
		bankcard.setOpeningBank(userModel.getOpeningBank());
		bankcard.setCreateTime(new Date());
		bankcard.setModifyTime(new Date());
		int rows = bankcardDao.insertSelective(bankcard);
		return rows;
	}

	/**
	 * 医生用户视图表
	 *
	 * @param currId
	 * @return
	 */
	@Override
	public UserDoctViewVo selectUserDoctView(Long currId) {
		return mapper.selectUserDoctView(currId);
	}

}
